package com.gin.kotlin.vegetables_kot.database.dao

import androidx.room.Dao
import androidx.room.Delete
import androidx.room.Insert
import androidx.room.OnConflictStrategy
import androidx.room.Query
import androidx.room.Update
import com.gin.kotlin.vegetables_kot.database.entity.VegetableLog

@Dao
interface VegetableLogDao {
    @Query(
        "select * from VegetableLog where 1=1  "
                + "and (:position is null or position==:position)"
                + "and (:typeV is null or typeV==:typeV)"
                + "and (:typeO is null or typeO==:typeO)"
                + "order by timeR desc limit :size offset (:page-1)*:size "
    )
    fun page(page: Int = 1, size: Int = 10, position: String? = null, typeV: String? = null, typeO: String? = null): List<VegetableLog>

    @Insert(onConflict = OnConflictStrategy.REPLACE)
    fun add(logs: List<VegetableLog>)

    @Delete
    fun del(entity: VegetableLog)

    @Update
    fun update(entity: VegetableLog)
}